package com.weilai.config;

import com.weilai.controller.Interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 配置类，用于注册拦截器
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                // 排除 Swagger 相关路径
                .excludePathPatterns(
                        "/swagger-ui.html",          // Swagger 界面
                        "/webjars/**",              // Swagger 静态资源
                        "/swagger-resources/**",     // Swagger 资源文件
                        "/v2/api-docs",              // API 元数据
                        "/configuration/**",        // Swagger 配置

                        "/css/**", "/js/**", "/img/**",
                        "/login/**", "/index", "/login",
                        "/register/**","/forgetPassword/sendCode","/forgetPassword",
                        "/mainPageRecommend", "/mainPageTrending","/mainPageAttention","/mainPageVedio"

                );
    }

    //如果要设置根路径映射，则拦截器不可放行"/"
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 将根路径映射到登录页面视图
        registry.addViewController("/").setViewName("redirect:/login");
    }

}